package com.hp.bon.sgw.wh.channel.invoices;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.hp.bon.sgw.wh.channel.invoices.bizSlot.IssueInvoiceSlot;
import com.hp.bon.sgw.wh.channel.invoices.bizSlot.OrderOneItemSlot;
import com.hp.bon.sgw.wh.channel.invoices.bizSlot.PaymentSlot;
import com.hp.bon.sgw.wh.channel.invoices.bizSlot.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class InvoiceBizRouter {
	
	private static final Logger _log = LoggerFactory.getLogger(InvoiceBizRouter.class);
	
	private Map<String, BizSlot> slotRepositories = new HashMap<String, BizSlot>();
	
	public void init()	{
		// 账单API- monthlyBill
		String monthlyBillKey = "/ws/SGWService/monthlyBill@GET";
		BizSlot monthlyBillBizSlot = new MonthlyBillSlot();
		slotRepositories.put(monthlyBillKey, monthlyBillBizSlot);

		// 缴费API—payment
		String  paymentKey="/ws/SGWService/payment@GET";
		PaymentSlot paymentSlot = new PaymentSlot();
		slotRepositories.put(paymentKey, paymentSlot);

		// 营业厅订单API- orderOneItem
		String  orderOneItemKey="/ws/SGWService/orderOneItem@GET";
		OrderOneItemSlot orderOneItemSlot = new OrderOneItemSlot();
		slotRepositories.put(orderOneItemKey, orderOneItemSlot);

		// 开票API—issueInvoice
		String  issueInvoiceKey="/ws/SGWService/issueInvoice@POST";
		IssueInvoiceSlot issueInvoiceSlot = new IssueInvoiceSlot();
		slotRepositories.put(issueInvoiceKey, issueInvoiceSlot);
		// 查询发票API-invoice
		String invoiceKey = "/ws/SGWService/invoice@GET";
		BizSlot invoiceSlot = new InvoiceGetSlot();
		slotRepositories.put(invoiceKey, invoiceSlot);
		// 查询开票信息API-invoiceinfomation
		String invoiceInformationGetKey = "/ws/SGWService/invoiceInformation@GET";
		BizSlot invoiceInformationGetSlot = new InvoiceInformationGetSlot();
		slotRepositories.put(invoiceInformationGetKey, invoiceInformationGetSlot);
		// 新增开票信息API-invoiceinfomation
		String invoiceInformationPostKey = "/ws/SGWService/invoiceInformation@POST";
		BizSlot invoiceInformationPostSlot = new InvoiceInformationPostSlot();
		slotRepositories.put(invoiceInformationPostKey, invoiceInformationPostSlot);
		// 新增开票信息API-invoiceinfomation
		String invoiceInformationPatchKey = "/ws/SGWService/invoiceInformation@PATCH";
		BizSlot invoiceInformationPatchSlot = new InvoiceInformationPatchSlot();
		slotRepositories.put(invoiceInformationPatchKey, invoiceInformationPatchSlot);
	}
	
	public BizSlot routeBizSlot(String requestPath, String requestMethod) {
		if (requestPath.indexOf("/ws/SGWService/invoiceInformation")>=0) {
			requestPath = "/ws/SGWService/invoiceInformation";
		}
		String key = requestPath + "@" + requestMethod.toUpperCase();
		BizSlot bizSlot =  slotRepositories.get(key);
		if(null == bizSlot) {
			_log.error("none bizSlot,requestPath={},requestMethod={}",requestPath,requestMethod);
			Set<Entry<String, BizSlot>> entries = slotRepositories.entrySet();
			for(Entry<String, BizSlot> entry : entries) {
				_log.info("bizSlot, key={}, clz={}", entry.getKey(), entry.getValue().getClass());
			}
		}
		return bizSlot;
	}
	
}
